package jinbo.cn.com.dao;

import jinbo.cn.com.util.DataSourceDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * Created by songxiaohu on 2018/2/27.
 */
@Component
public class SpringDemoDao {

    //数据库连接池中获取的数据库链接
    @Autowired
    private DataSourceDao dataSourceDao;
    //查询list集合的demo
    public List<Map<String,Object>> getList(){
        String sql="select * from User";
        return dataSourceDao.execQuery(sql,new Object[]{});
    }

    //查询Map的demo
    public Map<String,Object> getMap(){
        String sql="select * from User where userid=1";
        return dataSourceDao.execQueryOne(sql,new Object[]{});
    }

    //执行更新的demo
    public int isUpdate(){
        String sql="update User set Name='a' where id=13";
        return dataSourceDao.execUpdate(sql,new Object[]{});
    }
    //执行插入的demo
    public int isInsert(){
        String sql="insert into  User (id,login_name,name,password,salt,sex,age," +
                "phone,user_type,status,organization_id,create_time)values(null,?,?,?,?,?,?,?,?,?,?,now())";
        return dataSourceDao.execUpdate(sql,new Object[]{"xiaoli","李可","a123456","23","1",15,"12319098374",1,1,1});
    }
}
